
<!DOCTYPE html
  PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   <!--
This HTML was auto-generated from MATLAB code.
To make changes, update the MATLAB code and republish this document.
      --><title>estimaStates</title><meta name="generator" content="MATLAB 7.11"><link rel="schema.DC" href="http://purl.org/dc/elements/1.1/"><meta name="DC.date" content="2012-01-16"><meta name="DC.source" content="estimaStates.m"><style type="text/css">

body {
  background-color: white;
  margin:10px;
}

h1 {
  color: #990000; 
  font-size: x-large;
}

h2 {
  color: #990000;
  font-size: medium;
}

/* Make the text shrink to fit narrow windows, but not stretch too far in 
wide windows. */ 
p,h1,h2,div.content div {
  max-width: 600px;
  /* Hack for IE6 */
  width: auto !important; width: 600px;
}

pre.codeinput {
  background: #EEEEEE;
  padding: 10px;
}
@media print {
  pre.codeinput {word-wrap:break-word; width:100%;}
} 

span.keyword {color: #0000FF}
span.comment {color: #228B22}
span.string {color: #A020F0}
span.untermstring {color: #B20000}
span.syscmd {color: #B28C00}

pre.codeoutput {
  color: #666666;
  padding: 10px;
}

pre.error {
  color: red;
}

p.footer {
  text-align: right;
  font-size: xx-small;
  font-weight: lighter;
  font-style: italic;
  color: gray;
}

  </style></head><body><div class="content"><h2>Contents</h2><div><ul><li><a href="#1">estimaStates</a></li><li><a href="#2">1. Kalman filter and State decomposition</a></li><li><a href="#3">2.a Decomposition for observables, grouped by Observables, that shock Only</a></li><li><a href="#4">2.b Decomposition for observables, grouped by Observables, that shock Only</a></li><li><a href="#5">3.a Decomposition for states, grouped by Observables</a></li><li><a href="#6">4. Plot of Innovations</a></li><li><a href="#7">5. Plot of Selected States</a></li><li><a href="#8">6. Decomposition of observables for selected subsamples</a></li><li><a href="#10">Observables Organized By series</a></li><li><a href="#11">Observables Organized By Shocks</a></li><li><a href="#13">States Organized By Series</a></li><li><a href="#16">7. Table with States and Innovations in Filter</a></li></ul></div><h2>estimaStates<a name="1"></a></h2><pre class="codeinput">cd(cucd);
</pre><pre class="codeoutput">Undefined function or variable 'cucd'.

Error in ==&gt; estimaStates at 4
cd(cucd); 
</pre><h2>1. Kalman filter and State decomposition<a name="2"></a></h2><pre class="codeinput">[KFStru,logL]=feval(addsol.funcKfilter,parMode,funcmod,Y,trainvec,solveopt,addsol);
</pre><h2>2.a Decomposition for observables, grouped by Observables, that shock Only<a name="3"></a></h2><pre class="codeinput">clear <span class="string">inStru</span>
inStru.caseDecomp=<span class="string">'single'</span>;
inStru.orgBy=<span class="string">'series'</span>;
graphMat=DecompSeries(Y,funcmod,parMode,solveopt,addsol,inStru,KFStru,sampleSS,[],nameStru);
compileGraphsPDF(graphMat,<span class="string">'Decomp Obs by Series'</span>,outpath);
close <span class="string">all</span>;
</pre><h2>2.b Decomposition for observables, grouped by Observables, that shock Only<a name="4"></a></h2><pre class="codeinput">inStru.caseDecomp=<span class="string">'single'</span>;
inStru.orgBy=<span class="string">'shocks'</span>;
graphMat=DecompSeries(Y,funcmod,parMode,solveopt,addsol,inStru,KFStru,sampleSS,[],nameStru);
compileGraphsPDF(graphMat,<span class="string">'Decomp Obs by Shocks'</span>,outpath);
close <span class="string">all</span>;
</pre><h2>3.a Decomposition for states, grouped by Observables<a name="5"></a></h2><pre class="codeinput"><span class="keyword">if</span> flag.stateDecomp==true
    clear <span class="string">inStru</span>
    inStru.caseDecomp=<span class="string">'single'</span>;
    inStru.orgBy=<span class="string">'series'</span>;
    inStru.extract=report.stateDecomp;
    graphMat=DecompSeries([],funcmod,parMode,solveopt,addsol,inStru,KFStru,sampleSS,[],nameStru);
    compileGraphsPDF(graphMat,<span class="string">'Decomp States by Series'</span>,outpath);
    close <span class="string">all</span>;
<span class="keyword">end</span>
</pre><h2>4. Plot of Innovations<a name="6"></a></h2><pre class="codeinput">nameStru.colNames=shockNames;
clear <span class="string">graphStru</span>;
graphStru.suptitle=<span class="string">'Innovations'</span>;
graphStru.subtitle=outpath;
graphStru.subtitleFontSize=9;
handlesInnovations=plotStates(KFStru.innovations,sampleSS,graphStru,nameStru);
compileGraphsPDF(handlesInnovations,<span class="string">'Innovations'</span>,outpath);
clear <span class="string">graphStru</span> <span class="string">handlesInnovations</span>;
</pre><h2>5. Plot of Selected States<a name="7"></a></h2><pre class="codeinput"><span class="keyword">if</span> flag.stateDecomp==true
    clear <span class="string">graphStru</span>;
    graphStru.suptitle=<span class="string">'Smooth States'</span>;
    graphStru.subtitle=outpath;
    graphStru.subtitleFontSize=9;
    <span class="comment">%graphStru.extract=report.stateDecomp;</span>
    nameStru.colNames=report.stateDecomp;
    tempMat=KFStru.smoothSt(:,report.stateDecompPos);
    handlesStates=plotStates(tempMat,sampleSS,graphStru,nameStru);
    compileGraphsPDF(handlesStates,<span class="string">'States'</span>,outpath);
    clear <span class="string">graphStru</span> <span class="string">handlesStates</span>;
<span class="keyword">end</span>
</pre><h2>6. Decomposition of observables for selected subsamples<a name="8"></a></h2><pre class="codeinput"><span class="keyword">if</span> flag.subSamples==1;
    NSub=size(report.subSamples,1);
    clear <span class="string">inStru</span>
    inStru.caseDecomp=<span class="string">'single'</span>;
    <span class="keyword">for</span> ii=1:NSub
</pre><pre class="codeinput">        tempPos=(report.subSamplePos(ii,1):subSamplePos(ii,2));
        tempKFStru.countObs=KFStru.countObs(tempPos,:,:);
        tempSampleStru.sampleVec=SS.sampleVec(tempPos);
</pre><h2>Observables Organized By series<a name="10"></a></h2><pre class="codeinput">        inStru.orgBy=<span class="string">'series'</span>;
        graphMat=DecompSeries(Y(tempPos,:),funcmod,parMode,solveopt,addsol,<span class="keyword">...</span>
            inStru,tempKFStru,tempSampleStru,[],nameStru);
        compileGraphsPDF(graphMat,[<span class="string">'Decomp Obs by Series '</span>,tempString],outpath);
        clear <span class="string">graphMat</span>
        close <span class="string">all</span>;
</pre><h2>Observables Organized By Shocks<a name="11"></a></h2><pre class="codeinput">        inStru.orgBy=<span class="string">'shocks'</span>;
        graphMat=DecompSeries(Y(tempPos,:),funcmod,parMode,solveopt,addsol,<span class="keyword">...</span>
            inStru,tempKFStru,tempSampleStru,[],nameStru);
        compileGraphsPDF(graphMat,[<span class="string">'Decomp Obs by Shocks '</span>,tempString],outpath);
        clear <span class="string">graphMat</span>
        close <span class="string">all</span>;
        <span class="keyword">if</span> flag.stateDecomp==true
</pre><pre class="codeinput">            inStru.caseDecomp=<span class="string">'single'</span>;
            tempKFStru.countSt=KFStru.countSt(tempPos,:,:);
            inStru.orgBy=<span class="string">'series'</span>;
            inStru.extract=report.stateDecomp;
</pre><h2>States Organized By Series<a name="13"></a></h2><pre class="codeinput">            graphMat=DecompSeries([],funcmod,parMode,solveopt,addsol,inStru,tempKFStru,<span class="keyword">...</span>
                tempSampleStru,[],nameStru);
            compileGraphsPDF(graphMat,[<span class="string">'Decomp States by Series '</span>,tempString],outpath);
            close <span class="string">all</span>;
</pre><pre class="codeinput">        <span class="keyword">end</span>
</pre><pre class="codeinput">    <span class="keyword">end</span>
<span class="keyword">end</span>
clear <span class="string">graphMat</span> <span class="string">inStru</span> <span class="string">temp*</span> <span class="string">NSub</span>;
</pre><h2>7. Table with States and Innovations in Filter<a name="16"></a></h2><pre class="codeinput">cd(outpath);
xlswrite(<span class="string">'correlation Innovations'</span>,crtcell(corrcoef(KFStru.innovations),shockNames,shockNames,<span class="keyword">...</span>
    {<span class="string">'Correlation'</span>}),<span class="string">'Filter'</span>);
xlswrite(<span class="string">'smooth States'</span>,crtcell(KFStru.smoothSt,SS.sampleCell,nameStru.stateNames,<span class="keyword">...</span>
    {<span class="string">'Smooth States'</span>}),<span class="string">'Filter'</span>);
xlswrite(<span class="string">'smooth States'</span>,crtcell(KFStru.innovations,SS.sampleCell,nameStru.shockNames,<span class="keyword">...</span>
    {<span class="string">'Smooth Innovations'</span>}),<span class="string">'Filter'</span>);
cd(cucd);
disp(<span class="string">'Turn me into a TEX Table'</span>);


<span class="comment">% Recall POS_DECOMPSTATES and DECOMPSTATES_NAMES are different from ZNAMES</span>
<span class="comment">% and POS_OBSINSTATES in that they adjust to plot the cummulators at the</span>
<span class="comment">% end</span>
<span class="comment">% close all;</span>
<span class="comment">% deleteFile('Decomposition by Series.ps',outpath);</span>
<span class="comment">% graphStru.mode='cols';</span>
<span class="comment">% graphStru.legend={'Data','CounterFactual'} ;</span>
<span class="comment">% graphStru.xaxis=sample;</span>
<span class="comment">% graphStru.colNames=nameStru.obsNames;</span>
<span class="comment">% nameStru.pageNames=nameStru.shockNames;</span>
<span class="comment">% plotColsOrPages(Ydem,KFStru.countObs,junkStru,nameStru)</span>
</pre><pre class="codeinput"><span class="comment">% Ydem=demeanDSGEY(Y,funcmod,parmode_top,solveopt,addsol);</span>
<span class="comment">% subSample=2000.00:2005.00;</span>
<span class="comment">% posSubSample=(find( sample==subSample(1) ):find( sample==subSample(end) ));</span>
<span class="comment">% fakeSample.sampleVec=sample(posSubSample);</span>
<span class="comment">% graphStru.NYears=6;</span>
<span class="comment">% for ii=1:length(nameStru.obsNames);</span>
<span class="comment">%     graphStru.suptitle=nameStru.obsNames(ii);</span>
<span class="comment">%     figsHandle=plotDecompPerSeries(Ydem(posSubSample,ii),squeeze(KFStru.countObs(posSubSample,ii,:)),...</span>
<span class="comment">%         fakeSample,graphStru,nameStru);</span>
<span class="comment">%     cd(outpath);</span>
<span class="comment">%     for jj=1:length(figsHandle);</span>
<span class="comment">%         if ii== 1 &amp;&amp; jj==1</span>
<span class="comment">%             print(figsHandle(jj),'-dpsc','Decomposition by Series SubSamp');</span>
<span class="comment">%         else</span>
<span class="comment">%             print(figsHandle(jj),'-dpsc','Decomposition by Series SubSamp','-append');</span>
<span class="comment">%         end</span>
<span class="comment">%     end</span>
<span class="comment">% cd(cucd);</span>
<span class="comment">% end</span>



<span class="comment">% %% Plot per shock</span>
<span class="comment">% %pospershock=cellposition({'unemployment','finding','separation','vacancies','gdp','I','C'},stanames);</span>
<span class="comment">% pospershock=cellposition(znames,stanames);</span>
<span class="comment">%</span>
<span class="comment">% %% Decomposition with Neutral and MEI shocks only</span>
<span class="comment">% % [figvec_zphi,decmat_zphi,vrat_zphi]=plot_decompositions_pergroup_mixfreq(smooth_st(:,pos_decompstates),countmat(:,pos_decompstates,:),decompstates_names,shonames,{'Neutral technology','MEI'},'Neutral and MEI shocks only',0.1,0,indecomp);</span>
<span class="comment">% % cd(outpath);</span>
<span class="comment">% % print(figvec_zphi,'-dpdf','Neutral MEI only');</span>
<span class="comment">% % cd(cucd);</span>
<span class="comment">%</span>
<span class="comment">%</span>
<span class="comment">%</span>
<span class="comment">%</span>
<span class="comment">% %% Decomposition with all but measurement errors</span>
<span class="comment">%</span>
<span class="comment">% % [figvec_nome,decmat_nome,vrat_nome]=plot_decompositions_pergroup_mixfreq(smooth_st(:,pos_decompstates),countmat(:,pos_decompstates,:),decompstates_names,shonames,{'Neutral technology','MEI','Job destruction','Discount factor','Aggregate demand','Matching'},'All but measurement errors',0.1,0,indecomp);</span>
<span class="comment">% %</span>
<span class="comment">% % indecomp.decompmat_zphi=decmat_zphi;</span>
<span class="comment">% % indecomp.vratio_zphi =vrat_zphi;</span>
<span class="comment">% % indecomp.decompnames=decompstates_names;</span>
<span class="comment">% % indecomp.label_zphi={'Neutral &amp; MEI Only'};</span>
<span class="comment">% % indecomp.actual    =smooth_st(:,pos_decompstates);</span>
<span class="comment">% % indecomp.vratio_nome=vrat_nome;</span>
<span class="comment">% %</span>
<span class="comment">% % cd(outpath);</span>
<span class="comment">% % print(figvec_zphi,'-dpdf','All but Measurement errors');</span>
<span class="comment">% % save counterfactuals indecomp smooth_st pos_decompstates countmat;</span>
<span class="comment">% % cd(cucd);</span>
<span class="comment">%</span>
<span class="comment">%</span>
<span class="comment">% figvec=plot_decompositions_pershock(smooth_st(:,pospershock),countmat(:,pospershock,:),stanames(pospershock),shonames,sample,[znames{ii},': decomposition per shock'],0.2,0);</span>
<span class="comment">% cd(outpath);</span>
<span class="comment">% for ii=1:length(znames);</span>
<span class="comment">%     if ii == 1;</span>
<span class="comment">%         print(figvec(ii),'-dpsc','decomposition series');</span>
<span class="comment">%     else</span>
<span class="comment">%         print(figvec(ii),'-dpsc','decomposition series','-append');</span>
<span class="comment">%     end</span>
<span class="comment">% end</span>
<span class="comment">% cd(cucd);</span>

<span class="comment">% Create table with the states and innovations</span>
<span class="comment">% cd(outpath);</span>
<span class="comment">% save statemat smooth_st stt stanames shonames etamat;</span>
<span class="comment">% if flag_mixfreq==1</span>
<span class="comment">%     outputcell = crtcell(smooth_st(:,1:end-out.nzLF),num2cprec(sample),stanames,{'SmoothStates'});</span>
<span class="comment">% else</span>
<span class="comment">%     outputcell = crtcell(smooth_st,num2cprec(sample),stanames,{'Smooth States'});</span>
<span class="comment">% end</span>
<span class="comment">%</span>
<span class="comment">% if ~isunix</span>
<span class="comment">%     xlswrite('tab states',outputcell,'SmoothSt');</span>
<span class="comment">% else</span>
<span class="comment">%     savecell(outputcell,[],outpath,['tab states', '_', 'SmoothSt']);</span>
<span class="comment">% end</span>
<span class="comment">% if ~isunix</span>
<span class="comment">%     xlswrite('tab states',crtcell(etamat,num2cprec(sample),shonames,{'Smooth Innovation'}),'SmoothEta');</span>
<span class="comment">% else</span>
<span class="comment">%     savecell(crtcell(etamat,num2cprec(sample),shonames,{'Smooth Innovation'}), ...</span>
<span class="comment">%         [], outpath, ['tab states', '_','SmoothEta']);</span>
<span class="comment">% end</span>
<span class="comment">% cd(cucd);</span>
<span class="comment">%</span>
<span class="comment">% %% Plot stochastic shocks and their innovations</span>
<span class="comment">% % Shocks_sel variable must be defined in the Settings.m file</span>
<span class="comment">% if exist('shocks_sel','var')==1 &amp;&amp; ~isempty(shocks_sel)</span>
<span class="comment">%     stshocks_pos=cellposition(shocks_sel,stanames);</span>
<span class="comment">%     figvec=zeros( length(shocks_sel) );</span>
<span class="comment">%     for ii=1:length(shocks_sel);</span>
<span class="comment">%         figvec(ii)=figure;</span>
<span class="comment">%         subplot(2,1,1);</span>
<span class="comment">%         plot(sample,smooth_st(:,stshocks_pos(ii)),'LineWidth',2 );</span>
<span class="comment">%         title([shocks_sel{ii},': exogenous process'],'FontSize',14);</span>
<span class="comment">%         xlim([sample(1) sample(end)+0.1]);</span>
<span class="comment">%         nberdates_ajd('y');</span>
<span class="comment">%         subplot(2,1,2);</span>
<span class="comment">%         plot(sample,etamat(:,ii),'LineWidth',2 );</span>
<span class="comment">%         title([shonames{ii},': innovations'],'FontSize',14);</span>
<span class="comment">%         xlim([sample(1) sample(end)+0.1]);</span>
<span class="comment">%         subtitulo(extrsubf(outpath,cucd));</span>
<span class="comment">%     end</span>
<span class="comment">%     cd(outpath);</span>
<span class="comment">%     for ii=1:length(shocks_sel);</span>
<span class="comment">%         if ii == 1;</span>
<span class="comment">%             print(figvec(ii),'-dpsc','Shocks');</span>
<span class="comment">%         else</span>
<span class="comment">%             print(figvec(ii),'-dpsc','Shocks','-append');</span>
<span class="comment">%         end</span>
<span class="comment">%     end</span>
<span class="comment">%     if ~isunix</span>
<span class="comment">%         ps2pdf('psfile', 'Shocks.ps', 'pdffile', 'Shocks.pdf', 'deletepsfile',1);</span>
<span class="comment">%     end</span>
<span class="comment">% end</span>
<span class="comment">% cd(cucd);</span>
</pre><p class="footer"><br>
      Published with MATLAB&reg; 7.11<br></p></div><!--
##### SOURCE BEGIN #####
%% estimaStates 
% 
%
cd(cucd); 

%% 1. Kalman filter and State decomposition 
[KFStru,logL]=feval(addsol.funcKfilter,parMode,funcmod,Y,trainvec,solveopt,addsol); 

%% 2.a Decomposition for observables, grouped by Observables, that shock Only
clear inStru
inStru.caseDecomp='single'; 
inStru.orgBy='series'; 
graphMat=DecompSeries(Y,funcmod,parMode,solveopt,addsol,inStru,KFStru,sampleSS,[],nameStru); 
compileGraphsPDF(graphMat,'Decomp Obs by Series',outpath); 
close all; 

%% 2.b Decomposition for observables, grouped by Observables, that shock Only 
inStru.caseDecomp='single'; 
inStru.orgBy='shocks'; 
graphMat=DecompSeries(Y,funcmod,parMode,solveopt,addsol,inStru,KFStru,sampleSS,[],nameStru); 
compileGraphsPDF(graphMat,'Decomp Obs by Shocks',outpath); 
close all; 

%% 3.a Decomposition for states, grouped by Observables
if flag.stateDecomp==true    
    clear inStru
    inStru.caseDecomp='single';
    inStru.orgBy='series';
    inStru.extract=report.stateDecomp; 
    graphMat=DecompSeries([],funcmod,parMode,solveopt,addsol,inStru,KFStru,sampleSS,[],nameStru);
    compileGraphsPDF(graphMat,'Decomp States by Series',outpath);
    close all;
end 
    
%% 4. Plot of Innovations 
nameStru.colNames=shockNames; 
clear graphStru; 
graphStru.suptitle='Innovations'; 
graphStru.subtitle=outpath; 
graphStru.subtitleFontSize=9; 
handlesInnovations=plotStates(KFStru.innovations,sampleSS,graphStru,nameStru); 
compileGraphsPDF(handlesInnovations,'Innovations',outpath); 
clear graphStru handlesInnovations; 

%% 5. Plot of Selected States 
if flag.stateDecomp==true 
    clear graphStru;
    graphStru.suptitle='Smooth States';
    graphStru.subtitle=outpath;
    graphStru.subtitleFontSize=9;
    %graphStru.extract=report.stateDecomp; 
    nameStru.colNames=report.stateDecomp;
    tempMat=KFStru.smoothSt(:,report.stateDecompPos);
    handlesStates=plotStates(tempMat,sampleSS,graphStru,nameStru);
    compileGraphsPDF(handlesStates,'States',outpath); 
    clear graphStru handlesStates;
end 

%% 6. Decomposition of observables for selected subsamples
if flag.subSamples==1;
    NSub=size(report.subSamples,1);
    clear inStru
    inStru.caseDecomp='single';
    for ii=1:NSub
        tempPos=(report.subSamplePos(ii,1):subSamplePos(ii,2));
        tempKFStru.countObs=KFStru.countObs(tempPos,:,:);
        tempSampleStru.sampleVec=SS.sampleVec(tempPos);
        %% Observables Organized By series
        inStru.orgBy='series';
        graphMat=DecompSeries(Y(tempPos,:),funcmod,parMode,solveopt,addsol,...
            inStru,tempKFStru,tempSampleStru,[],nameStru);
        compileGraphsPDF(graphMat,['Decomp Obs by Series ',tempString],outpath);
        clear graphMat
        close all; 
        %% Observables Organized By Shocks
        inStru.orgBy='shocks';
        graphMat=DecompSeries(Y(tempPos,:),funcmod,parMode,solveopt,addsol,...
            inStru,tempKFStru,tempSampleStru,[],nameStru);
        compileGraphsPDF(graphMat,['Decomp Obs by Shocks ',tempString],outpath);
        clear graphMat
        close all; 
        if flag.stateDecomp==true
            inStru.caseDecomp='single';
            tempKFStru.countSt=KFStru.countSt(tempPos,:,:);
            inStru.orgBy='series';
            inStru.extract=report.stateDecomp;
            %% States Organized By Series
            graphMat=DecompSeries([],funcmod,parMode,solveopt,addsol,inStru,tempKFStru,...
                tempSampleStru,[],nameStru);
            compileGraphsPDF(graphMat,['Decomp States by Series ',tempString],outpath);
            close all;
        end
    end
end 
clear graphMat inStru temp* NSub; 

%% 7. Table with States and Innovations in Filter 
cd(outpath);
xlswrite('correlation Innovations',crtcell(corrcoef(KFStru.innovations),shockNames,shockNames,...
    {'Correlation'}),'Filter');
xlswrite('smooth States',crtcell(KFStru.smoothSt,SS.sampleCell,nameStru.stateNames,...
    {'Smooth States'}),'Filter');
xlswrite('smooth States',crtcell(KFStru.innovations,SS.sampleCell,nameStru.shockNames,...
    {'Smooth Innovations'}),'Filter');
cd(cucd);
disp('Turn me into a TEX Table');


% Recall POS_DECOMPSTATES and DECOMPSTATES_NAMES are different from ZNAMES
% and POS_OBSINSTATES in that they adjust to plot the cummulators at the
% end
% close all;
% deleteFile('Decomposition by Series.ps',outpath); 
% graphStru.mode='cols';          
% graphStru.legend={'Data','CounterFactual'} ;          
% graphStru.xaxis=sample; 
% graphStru.colNames=nameStru.obsNames; 
% nameStru.pageNames=nameStru.shockNames; 
% plotColsOrPages(Ydem,KFStru.countObs,junkStru,nameStru)

 
 
%%

% Ydem=demeanDSGEY(Y,funcmod,parmode_top,solveopt,addsol);
% subSample=2000.00:2005.00; 
% posSubSample=(find( sample==subSample(1) ):find( sample==subSample(end) ));
% fakeSample.sampleVec=sample(posSubSample); 
% graphStru.NYears=6; 
% for ii=1:length(nameStru.obsNames);
%     graphStru.suptitle=nameStru.obsNames(ii);
%     figsHandle=plotDecompPerSeries(Ydem(posSubSample,ii),squeeze(KFStru.countObs(posSubSample,ii,:)),...
%         fakeSample,graphStru,nameStru);
%     cd(outpath);
%     for jj=1:length(figsHandle);
%         if ii== 1 && jj==1 
%             print(figsHandle(jj),'-dpsc','Decomposition by Series SubSamp');
%         else
%             print(figsHandle(jj),'-dpsc','Decomposition by Series SubSamp','-append');
%         end
%     end
% cd(cucd); 
% end

 

% %% Plot per shock 
% %pospershock=cellposition({'unemployment','finding','separation','vacancies','gdp','I','C'},stanames); 
% pospershock=cellposition(znames,stanames); 
% 
% %% Decomposition with Neutral and MEI shocks only 
% % [figvec_zphi,decmat_zphi,vrat_zphi]=plot_decompositions_pergroup_mixfreq(smooth_st(:,pos_decompstates),countmat(:,pos_decompstates,:),decompstates_names,shonames,{'Neutral technology','MEI'},'Neutral and MEI shocks only',0.1,0,indecomp);
% % cd(outpath);
% % print(figvec_zphi,'-dpdf','Neutral MEI only');
% % cd(cucd);
% 
% 
% 
% 
% %% Decomposition with all but measurement errors
% 
% % [figvec_nome,decmat_nome,vrat_nome]=plot_decompositions_pergroup_mixfreq(smooth_st(:,pos_decompstates),countmat(:,pos_decompstates,:),decompstates_names,shonames,{'Neutral technology','MEI','Job destruction','Discount factor','Aggregate demand','Matching'},'All but measurement errors',0.1,0,indecomp);
% % 
% % indecomp.decompmat_zphi=decmat_zphi; 
% % indecomp.vratio_zphi =vrat_zphi; 
% % indecomp.decompnames=decompstates_names; 
% % indecomp.label_zphi={'Neutral & MEI Only'}; 
% % indecomp.actual    =smooth_st(:,pos_decompstates); 
% % indecomp.vratio_nome=vrat_nome; 
% % 
% % cd(outpath);
% % print(figvec_zphi,'-dpdf','All but Measurement errors');
% % save counterfactuals indecomp smooth_st pos_decompstates countmat; 
% % cd(cucd);
% 
% 
% figvec=plot_decompositions_pershock(smooth_st(:,pospershock),countmat(:,pospershock,:),stanames(pospershock),shonames,sample,[znames{ii},': decomposition per shock'],0.2,0);
% cd(outpath); 
% for ii=1:length(znames);
%     if ii == 1;
%         print(figvec(ii),'-dpsc','decomposition series'); 
%     else
%         print(figvec(ii),'-dpsc','decomposition series','-append'); 
%     end    
% end
% cd(cucd); 

% Create table with the states and innovations 
% cd(outpath); 
% save statemat smooth_st stt stanames shonames etamat; 
% if flag_mixfreq==1
%     outputcell = crtcell(smooth_st(:,1:end-out.nzLF),num2cprec(sample),stanames,{'SmoothStates'}); 
% else
%     outputcell = crtcell(smooth_st,num2cprec(sample),stanames,{'Smooth States'}); 
% end
% 
% if ~isunix
%     xlswrite('tab states',outputcell,'SmoothSt');
% else
%     savecell(outputcell,[],outpath,['tab states', '_', 'SmoothSt']);
% end
% if ~isunix
%     xlswrite('tab states',crtcell(etamat,num2cprec(sample),shonames,{'Smooth Innovation'}),'SmoothEta'); 
% else
%     savecell(crtcell(etamat,num2cprec(sample),shonames,{'Smooth Innovation'}), ...
%         [], outpath, ['tab states', '_','SmoothEta']); 
% end
% cd(cucd); 
% 
% %% Plot stochastic shocks and their innovations 
% % Shocks_sel variable must be defined in the Settings.m file 
% if exist('shocks_sel','var')==1 && ~isempty(shocks_sel)
%     stshocks_pos=cellposition(shocks_sel,stanames);
%     figvec=zeros( length(shocks_sel) );
%     for ii=1:length(shocks_sel);
%         figvec(ii)=figure;
%         subplot(2,1,1);
%         plot(sample,smooth_st(:,stshocks_pos(ii)),'LineWidth',2 );
%         title([shocks_sel{ii},': exogenous process'],'FontSize',14);
%         xlim([sample(1) sample(end)+0.1]);
%         nberdates_ajd('y');
%         subplot(2,1,2);
%         plot(sample,etamat(:,ii),'LineWidth',2 );
%         title([shonames{ii},': innovations'],'FontSize',14);
%         xlim([sample(1) sample(end)+0.1]);
%         subtitulo(extrsubf(outpath,cucd));
%     end
%     cd(outpath);
%     for ii=1:length(shocks_sel);
%         if ii == 1;
%             print(figvec(ii),'-dpsc','Shocks');
%         else
%             print(figvec(ii),'-dpsc','Shocks','-append');
%         end
%     end
%     if ~isunix
%         ps2pdf('psfile', 'Shocks.ps', 'pdffile', 'Shocks.pdf', 'deletepsfile',1);
%     end
% end
% cd(cucd); 
##### SOURCE END #####
--></body></html>